package org.piggy.core.netty.processor;

import org.piggy.core.Config;
import org.piggy.core.netty.wrapper.HttpRequestWrapper;
import org.piggy.core.disruptor.DisruptorQueueHandler;

public class DisruptorNettyProcessor implements NettyProcessor {

    private final DisruptorQueueHandler piggyQueueHandler;

    public DisruptorNettyProcessor(Config config, DefaultNettyProcessor defaultNettyProcessor) {
        DisruptorQueueHandler.Builder builder = new DisruptorQueueHandler.Builder().setThreads(config.getProcessThread());
        this.piggyQueueHandler = new DisruptorQueueHandler(builder, defaultNettyProcessor);
    }

    @Override
    public void process(HttpRequestWrapper wrapper) {
        this.piggyQueueHandler.add(wrapper);
    }

    @Override
    public void shutDown() {
       this.piggyQueueHandler.shutDown();
    }
}
